/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package services;

import com.google.gson.Gson;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.Booking;
import model.Flight;

/**
 *
 * @author Jorge
 */
public class ConcretePaymentService extends ContreteService implements PaymentService {

    public ConcretePaymentService() {
        super("http://localhost:8084/WebServiceFlightBooking/webresources/payment");
    }

    @Override
    public boolean makePayment(Booking booking) {
        try {
            
            URL recurso = new URL(urlBase);
            HttpURLConnection conexao = (HttpURLConnection) recurso.openConnection();
            conexao.setRequestMethod("POST");
            conexao.setRequestProperty("Content-Type", "application/json");
            conexao.setDoOutput(true);

            String envia = new Gson().toJson(booking).toString();
            
//            System.out.println(envia);

            conexao.connect();
            conexao.getOutputStream().write(envia.getBytes(), 0, envia.length());

            String res = lerInputStream(conexao.getInputStream());
            conexao.disconnect();
            System.out.println("res: "+res);
            Boolean bo = new Gson().fromJson(res, Boolean.class);

            return bo;

        } catch (IOException ex) {
            Logger.getLogger(ConcreteDatabaseService.class.getName()).log(Level.SEVERE, null, ex);

        }
        return false;
    }
}
